package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HistoryRp;
import com.ruoyi.system.service.IHistoryRpService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 历史考勤Controller
 * 
 * @author ruoyi
 * @date 2023-05-14
 */
@Controller
@RequestMapping("/system/rp")
public class HistoryRpController extends BaseController
{
    private String prefix = "system/rp";

    @Autowired
    private IHistoryRpService historyRpService;

    @RequiresPermissions("system:rp:view")
    @GetMapping()
    public String rp()
    {
        return prefix + "/rp";
    }

    /**
     * 查询历史考勤列表
     */
    @RequiresPermissions("system:rp:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HistoryRp historyRp)
    {
        startPage();
        List<HistoryRp> list = historyRpService.selectHistoryRpList(historyRp);
        return getDataTable(list);
    }

    /**
     * 导出历史考勤列表
     */
    @RequiresPermissions("system:rp:export")
    @Log(title = "历史考勤", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HistoryRp historyRp)
    {
        List<HistoryRp> list = historyRpService.selectHistoryRpList(historyRp);
        ExcelUtil<HistoryRp> util = new ExcelUtil<HistoryRp>(HistoryRp.class);
        return util.exportExcel(list, "历史考勤数据");
    }

    /**
     * 新增历史考勤
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存历史考勤
     */
    @RequiresPermissions("system:rp:add")
    @Log(title = "历史考勤", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HistoryRp historyRp)
    {
        return toAjax(historyRpService.insertHistoryRp(historyRp));
    }

    /**
     * 修改历史考勤
     */
    @RequiresPermissions("system:rp:edit")
    @GetMapping("/edit/{historyrpId}")
    public String edit(@PathVariable("historyrpId") Long historyrpId, ModelMap mmap)
    {
        HistoryRp historyRp = historyRpService.selectHistoryRpByHistoryrpId(historyrpId);
        mmap.put("historyRp", historyRp);
        return prefix + "/edit";
    }

    /**
     * 修改保存历史考勤
     */
    @RequiresPermissions("system:rp:edit")
    @Log(title = "历史考勤", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HistoryRp historyRp)
    {
        return toAjax(historyRpService.updateHistoryRp(historyRp));
    }

    /**
     * 删除历史考勤
     */
    @RequiresPermissions("system:rp:remove")
    @Log(title = "历史考勤", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(historyRpService.deleteHistoryRpByHistoryrpIds(ids));
    }
}
